#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long max_sum(vector<int> &num, int l, int r)
{
        if(l == r){
                return num[l];
        }

        if(l > r){
                return INT32_MIN;
        }

        int mid = (l + r) >> 1;
        long lmax = max_sum(num, l, mid);
        long rmax = max_sum(num, mid + 1, r);

        long sum = 0;
        long lm = INT32_MIN, rm = lm;
        for(int i = mid; i >= l; i--){
                sum += num[i];
                if(sum > lm){
                        lm = sum;
                }
        }

        sum = 0;
        for(int i = mid + 1; i <= r; i++){
                sum += num[i];
                if(sum > rm){
                        rm = sum;
                }
        }

        return max({lmax, rmax, lm + rm});
}

long dp_sum(vector<int> &num)
{
        long max_sum = INT64_MIN;
        vector<long> dp(num.size(), 0);
        dp[0] = num[0];

        for(int i = 1; i < num.size(); i++){
                dp[i] = max(dp[i - 1] + num[i], dp[i] + num[i]);
                max_sum = max(dp[i], max_sum);
        }

        return max_sum;
}

int main()
{
        int n = 0;
        cin >> n;
        vector<int> num(n, 0);
        for(int i = 0; i < n; i++){
                cin >> num[i];
        }

        //cout << max_sum(num, 0, n - 1) << endl;
        cout << dp_sum(num) << endl;
        return 0;
}